package cn.tedu.smartos.family_user.service.impl;

import cn.tedu.smartos.base.exception.ServiceException;
import cn.tedu.smartos.base.response.StatusCode;
import cn.tedu.smartos.family_user.mapper.ElderlyHealthMapper;
import cn.tedu.smartos.family_user.pojo.vo.BoundElderlyVO;
import cn.tedu.smartos.family_user.pojo.vo.ElderlyHealthInfoVO;
import cn.tedu.smartos.family_user.service.ElderlyHealthService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ElderlyHealthServiceImpl implements ElderlyHealthService {
    @Autowired
    private ElderlyHealthMapper elderlyHealthMapper;

    @Override
    public ElderlyHealthInfoVO getHealthInfo(Long elderlyUserId) {
        if (elderlyUserId == null) {
            throw new ServiceException(StatusCode.INVALID_REQUEST, "老人用户ID不能为空");
        }

        ElderlyHealthInfoVO healthInfo = elderlyHealthMapper.selectHealthInfoByElderlyUserId(elderlyUserId);
        if (healthInfo == null) {
            throw new ServiceException(StatusCode.USER_NOT_EXIT, "老人健康信息不存在");
        }
        return healthInfo;
    }

    @Override
    public List<BoundElderlyVO> listBoundElderly(Long familyUserId) {
        if (familyUserId == null) {
            throw new ServiceException(StatusCode.INVALID_REQUEST, "家属用户ID不能为空");
        }
        return elderlyHealthMapper.selectBoundElderlyByFamilyUserId(familyUserId);

    }
}